package com.lagou.rpc.pojo;

import lombok.*;

import java.util.Objects;

/**
 * 服务和服务对应的路径
 */
@AllArgsConstructor
@NoArgsConstructor
@Getter
@Setter
@ToString
public class ServerPath implements  Comparable<ServerPath> {

    //服务
    private Server server;

    //服务地址
    private String path;

    //进行比较
    @Override
    public int compareTo(ServerPath serverPath) {
        //当都为空的时候排序一致
        if(serverPath.server.getTime()==null&&this.server.getTime()==null){
            return 0;
        }
        //当存在一个为空时,空的排在前面
        if(serverPath.server.getTime()==null||this.server.getTime()==null){
            return this.server.getTime()==null?-1:1;
        }
        return this.server.getTime().compareTo(serverPath.server.getTime());
    }

    
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        ServerPath that = (ServerPath) o;
        return Objects.equals(path, that.path);
    }

    @Override
    public int hashCode() {
        return Objects.hash(path);
    }
}
